{ Google Code Jam 2011. Round 1C.
  Problemset: http://code.google.com/codejam/contest/dashboard?c=1128486
  Problem B.
  Verdict: Correct/Correct
}
uses
  SysUtils, Math;

const inf=round(1e16);

var
  test,tt,n,l,h,i,j,cur,cb,c,m:longint;
  a,cc,b:array[0..1000010] of int64;
  f:boolean;
  ans,time,gt,t:int64;

procedure sort(l,r:longint);
var
  i,j:longint;
  x,y:int64;
begin
i:=l;
j:=r;
x:=b[(l+r) div 2];
repeat
  while b[i]>x do inc(i);
  while b[j]<x do dec(j);
  if i<=j then begin
    y:=b[i];
    b[i]:=b[j];
    b[j]:=y;
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(test);
for tt:=1 to test do begin
  write('Case #',tt,': ');
  ans:=0;
  read(L,t,N,c);
  a[0]:=0;
  for i:=1 to c do read(cc[i]);
  cur:=1;
  for i:=1 to n do begin
    a[i]:=a[i-1]+cc[cur];
    cur:=cur mod c+1;
  end;
  m:=n+1;
  for i:=1 to n do
    if a[i]*2>=t then begin
      m:=i;
      break;
    end;
  cb:=0;
  if m<=n then begin
    b[1]:=a[m]-t div 2;
    cb:=1;
    for i:=m+1 to n do begin
      inc(cb);
      b[cb]:=a[i]-a[i-1];
    end;
    sort(1,cb);
  end;
  time:=a[n];
  gt:=0;
  for i:=1 to l do
    inc(gt,b[i]);
  dec(time,gt);
  ans:=time*2+gt;
  writeln(ans);
end;
end.
